using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace Daniel.Core.Models.Mapping
{
    public class GiftCardUsageHistoryMap : EntityTypeConfiguration<GiftCardUsageHistory>
    {
        public GiftCardUsageHistoryMap()
        {
            // Primary Key
            this.HasKey(t => t.Id);

            // Properties
            // Table & Column Mappings
            this.ToTable("GiftCardUsageHistory");
            this.Property(t => t.Id).HasColumnName("Id");
            this.Property(t => t.GiftCardId).HasColumnName("GiftCardId");
            this.Property(t => t.UsedWithOrderId).HasColumnName("UsedWithOrderId");
            this.Property(t => t.UsedValue).HasColumnName("UsedValue");
            this.Property(t => t.CreatedOnUtc).HasColumnName("CreatedOnUtc");

            // Relationships
            this.HasRequired(t => t.GiftCard)
                .WithMany(t => t.GiftCardUsageHistories)
                .HasForeignKey(d => d.GiftCardId);
            this.HasRequired(t => t.Order)
                .WithMany(t => t.GiftCardUsageHistories)
                .HasForeignKey(d => d.UsedWithOrderId);

        }
    }
}
